package cn.lhl.filter;

import cn.lhl.action.util.ActionUtil;
import cn.lhl.mvc.ActionMapping;
import cn.lhl.mvc.ActionProxy;
import cn.lhl.mvc.ConfigurationManager;
import cn.lhl.mvc.ServletActionContext;
import cn.lhl.result.ResultType;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by datou on 2017/3/16.
 */
public class Servlet extends HttpServlet {
    ConfigurationManager configurationManager=null;
    @Override
    public void init(ServletConfig config) throws ServletException {
        String urls=config.getInitParameter("config");
        String[] files=null;
        if(urls!=null){
            files=urls.split(",");
        }
        try {
            configurationManager=new ConfigurationManager(files);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletActionContext.setRequest(request);
        ServletActionContext.setResponse(response);
        ResultType.ifResultType(ActionUtil.getClassName(),configurationManager);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }


}
